using System.Net;
using PublicProject.PublicClass.Basics;
using PublicProject.PublicClass.OutPutModels;

namespace PublicProject.PublicMethods;
public static class OutPutMethod<T>
{
    /// <summary>
    /// 返回成功
    /// </summary>
    /// <param name="data">返回数据</param>
    /// <param name="errType">是否显示提示（1：显示，其余不显示）</param>
    /// <param name="message">提示信息</param>
    /// <returns></returns>
    public static OutputModel<T> Success(T data = default!, int errType = 0, string message = "操作成功")
    {
        OutputModel<T> outPutModel = new OutputModel<T>(true, errType, message, data);
        return outPutModel;
    }
    /// <summary>
    /// 返回失败
    /// </summary>
    /// <param name="message">提示信息</param>
    /// <param name="data">返回数据</param>
    /// <param name="statusCode">HTTP状态码</param>
    /// <returns></returns>
    public static OutputModel<T> Failure(string message = "操作失败", T data = default!, int statusCode = (int)HttpStatusCode.InternalServerError)
    {
        BaseHttpContext.Current.Response.StatusCode = statusCode;

        OutputModel<T> outPutModel = new OutputModel<T>(false, 1, message, data);

        return outPutModel;
    }
}